package com.partybuilding.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.partybuilding.annotation.DataScope;
import com.partybuilding.constants.SystemConstants;
import com.partybuilding.domain.entity.AdminRole;
import com.partybuilding.domain.entity.Admintable;
import com.partybuilding.domain.entity.Roletable;
import com.partybuilding.domain.entity.Usertable;
import com.partybuilding.mapper.AdminRoleMapper;
import com.partybuilding.service.AdminRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户-角色-作用域表(AdminRole)表服务实现类
 *
 * @author makejava
 * @since 2023-11-09 16:08:17
 */
@Service("adminRoleService")
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements AdminRoleService {

    /**
     * @param id
     * 在用户-角色-权限域表格中查询出该管理员所属的全部角色
     * 根据角色id查询
     * @return
     */
    @Override
    public List<AdminRole> getRolesById(String id) {
        LambdaQueryWrapper<AdminRole> lambdaQueryWrapper=new LambdaQueryWrapper();
        lambdaQueryWrapper
                .eq(AdminRole::getUser_id, id);
        List<AdminRole> adminRoles= list(lambdaQueryWrapper);
        return adminRoles;
    }

    /**
     * @param userId
     * @param branchesId
     * 通过用户id、支部id获取目前登录的角色，用于查询其相关权限和权限作用范围
     * @return
     */
    public AdminRole getRoleById(String userId,String branchesId){
        LambdaQueryWrapper<AdminRole> lambdaQueryWrapper=new LambdaQueryWrapper();
        lambdaQueryWrapper
                .eq(AdminRole::getUser_id, userId)
                .eq(AdminRole::getBranches_id,branchesId);
        AdminRole adminRole= getOne(lambdaQueryWrapper);
        return adminRole;
    }


}

